package LeetCode.leetcode977;

public class Review1 {
    public int[] sortedSquares(int[] nums) {
        int[] res = new int[nums.length];
        int l = 0;
        int r = nums.length-1;
        int k = nums.length-1;
        while (l <= r){
            int num1 = nums[l] * nums[l];
            int num2 = nums[r] * nums[r];
            if (num1 > num2){
                res[k--] = num1;
                l++;
            }else {
                res[k--] = num2;
                r--;
            }
        }
        return res;
    }
}
